package com.gwtjs.icustom.pojo;

import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author : [aGuang]
 * @version : [v1.0]
 * @className : UserEntity
 * @description : [用户实体类]
 * @createTime : [2022/11/18 14:57]
 * @updateUser : [aGuang]
 * @updateTime : [2022/11/18 14:57]
 * @updateRemark : [描述说明本次修改内容]
 */
@Entity //声明类为实体类
@Table(name="jpa_user")//对应创建之后的表名
public class UserEntity extends BaseEntity{
    @Id
    @Column(name = "user_code",columnDefinition = "bigint(20) COMMENT '学号'",nullable = false)//定义字段名和类型以及长度和备注，和是否允许为null
    private Long id;

    @Column(name="user_Name",nullable = false,columnDefinition = "varchar(32) COMMENT '用户名'")
    private String userName;
    @Column(name="pass_word",nullable = false,columnDefinition = "varchar(32) COMMENT '密码'")
    private String password;
    @Column(name="phone_Number",nullable = false,columnDefinition = "varchar(16) COMMENT '手机号'")
    private String phoneNumber;
    @Column(name="sex",columnDefinition = "varchar(2) COMMENT '性别'")
    private String sex;
    @Column(name="birthday",nullable = false,columnDefinition = "datetime COMMENT '生日日期'")
    @DateTimeFormat(pattern = "yyyy-MM-dd ")
    private Date birthday;

	//定义与ClassEntity之间的关联关系为一对多
	//cascade：该属性定义类和类之间的级联关系,cascade 的值只能从 CascadeType.PERSIST （级联新建）、 CascadeType.REMOVE （级联删除）、 CascadeType.REFRESH （级联刷新）、 CascadeType.MERGE （级联更新）中选择一个或多个。还有一个选择是使用 CascadeType.ALL ，表示选择全部四项。

    @OneToMany(cascade = CascadeType.ALL)
    //在保存关系中的表中，所保存关联的外键字段
    @JoinColumn(name="user_code")
    private List<ClassEntity>classEntities=new ArrayList<>();


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<ClassEntity> getClassEntities() {
        return classEntities;
    }

    public void setClassEntities(List<ClassEntity> classEntities) {
        this.classEntities = classEntities;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
}
